package com.ak.javaee.ejb;

import java.util.List;

import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;

import org.slf4j.Logger;

import com.ak.javaee.data.MemberRepository;
import com.ak.javaee.model.Member;

@org.jboss.ejb3.annotation.SecurityDomain("javaee6-app")
@Stateless
public class SLSBMemberBean {
	@Inject
	private Logger log;

	@Inject
	@MemberRepository
	private EntityManager em;

	@Inject
	private UserTransaction tx;

	@Resource
	SessionContext sctx;

	@RolesAllowed("businessowner")
	public List getMembers() {
		// Create the client
		System.out.println("Caller : " + sctx.getCallerPrincipal().getName());
		System.out.println("Caller is in Role : "
				+ sctx.isCallerInRole("businessowner"));
		final List<Member> results = em.createQuery(
				"select m from Member m order by m.name").getResultList();
		return results;

	}

 
}
